﻿/*
 * 创建者:  ideapadqiao\qiaojianhui
 * 邮件:    qiaojianhui@cont.com.cn
 * 功能描述: 
 * 历史记录: created by qiaojianhui 2012/2/26 16:41:37  
 *           
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace oqis.gis.frame.controls
{
   
    public class QGUCMapControl : QGUCBase
    {
        #region 成员变量


        #endregion

        #region 类构建与初始化

        /// <summary>
        /// 类构建
        /// </summary>
        public QGUCMapControl()
        {
            InitializeComponent();
                       
            this.mAxMap.Dock = System.Windows.Forms.DockStyle.Fill;
    
         }
        

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(QGUCMapControl));
            this.mAxMap = new AxMapWinGIS.AxMap();
            ((System.ComponentModel.ISupportInitialize)(this.mAxMap)).BeginInit();
            this.SuspendLayout();
            // 
            // axMapCtrl
            // 
            this.mAxMap.Enabled = true;
            this.mAxMap.Location = new System.Drawing.Point(15, 13);
            this.mAxMap.Name = "axMapCtrl";
            this.mAxMap.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapCtrl.OcxState")));
            this.mAxMap.Size = new System.Drawing.Size(111, 112);
            this.mAxMap.TabIndex = 0;
            // 
            // QGUCMapControl
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.Controls.Add(this.mAxMap);
            this.Name = "QGUCMapControl";
            ((System.ComponentModel.ISupportInitialize)(this.mAxMap)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        #region 类属性

        /// <summary>
        /// 地图控件
        /// </summary>
        public AxMapWinGIS.AxMap AxMap { get { return this.mAxMap; } }

        #endregion

        #region 类方法

        /// <summary>
        /// 添加文件至图层
        /// </summary>
        /// <param name="shpFile"></param>
        /// <returns></returns>
        public int AddLayer(string shpFile)
        {
            // 得到图层的源数据
            MapWinGIS.Shapefile shapeFile = new MapWinGIS.Shapefile();
 
            // 得到图层对象
            shapeFile.Open(shpFile, null);
            int handler = this.mAxMap.AddLayer(shapeFile , true);
            
            // 得到文件名
            string fileName = System.IO.Path.GetFileNameWithoutExtension(shpFile);
            // 设置图层名称
            mAxMap.set_LayerName(handler, fileName);

            // 抛出事件
            OnLayerAdded(handler);

            // 返回值
            return handler;
        }

        /// <summary>
        /// 删除指定的图层
        /// </summary>
        /// <param name="layerHandler"></param>
        /// <returns></returns>
        public void RemoveLayer(int layerHandler)
        {
            mAxMap.RemoveLayer(layerHandler);

            OnLayerRemoved(layerHandler);
        }
        
        /// <summary>
        /// 删除指定名称的图层
        /// </summary>
        /// <param name="layerName"></param>
        public void RemoveLayer(string layerName){
        }
        
        /// <summary>
        /// 清除图层
        /// </summary>
        public void ClearLayers(){ 
        	mAxMap.RemoveAllLayers();
            OnLayerCleared();
        }
        
        /// <summary>
        /// 图层移动
        /// </summary>
        /// <param name="fromIndex"></param>
        /// <param name="toIndex"></param>
        public void MoveLayer(int fromIndex,int toIndex){
        	mAxMap.MoveLayer(fromIndex,toIndex);
        	OnLayerMoved(0);
        }
        #endregion

        #region 类事件

        #region 添加图层事件

        /// <summary>
        /// 定义事件
        /// </summary>
        public event LayerAddedHandler LayerAdded;
        
        /// <summary>
        /// 事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnLayerAdded(object sender) {
            LayerAddedHandler handler = LayerAdded;

            if (handler != null) handler(sender);
        }

        #endregion

        #region 删除图层事件
        
        public event LayerRemovedHandler LayerRemoved;
        
        /// <summary>
        /// 事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnLayerRemoved(object layerName){
        	LayerRemovedHandler handler=LayerRemoved;
            if (handler != null) handler(layerName);
        }
        
        #endregion

        #region 清空图层事件

        public event LayerClearHandler LayerCleared;

        public void OnLayerCleared() {
            LayerClearHandler handler = LayerCleared;
            if (handler != null) handler();
        }

        #endregion
        
        #region 移动图层事件

        public event LayerMovedHandler LayerMoved;

        public void OnLayerMoved(object layerHandler) {
            LayerMovedHandler handler = LayerMoved;
            if (handler != null) handler(layerHandler);
        }

        #endregion

        #endregion

    }
}
